<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // exec
    let text = "mom and dad and baby";
    let pattern = /mom( and dad( and baby)?)?/gi;
    let matches = pattern.exec(text);
    console.log(matches.index);
    console.log(matches.input);
    console.log(matches[0]);
    console.log(matches[1]);
    console.log(matches[2]);

    // test

    // 正则其他方法跳过
</script>
</body>
</html>